package com.example.universitylibraryback.pipeline.filter;

import com.example.universitylibraryback.pipeline.BorrowContext;
import com.example.universitylibraryback.pipeline.Filter;
import org.springframework.stereotype.Component;
import java.util.concurrent.BlockingQueue;

@Component
public class ValidationFilter implements Filter<BorrowContext> {
    @Override
    public void process(BlockingQueue<BorrowContext> inputQueue, BlockingQueue<BorrowContext> outputQueue) throws InterruptedException {
        while (true) {
            BorrowContext context = inputQueue.take();
            if (context.getReaderId() == null || context.getReaderId().isEmpty()) {
                context.setValid(false);
                context.setErrorMsg("读者证号不能为空");
            } else if (context.getBookId() == null || context.getBookId().isEmpty()) {
                context.setValid(false);
                context.setErrorMsg("图书ID不能为空");
            }
            outputQueue.put(context);
        }
    }
}